package org.kabeja.parser.objects;

import org.kabeja.dxf.DXFConstants;
import org.kabeja.dxf.objects.DXFLayout;
import org.kabeja.dxf.objects.DXFObject;
import org.kabeja.parser.DXFValue;

/**
 * @author shutao
 * @since 2022/4/25 12:25
 */
public class DXFLayoutHandler extends DXFPlotsettingsHandler {
    public static final int GROUPCODE_MINIMUM_LIMITS_X = 10;
    public static final int GROUPCODE_MINIMUM_LIMITS_Y = 20;
    public static final int GROUPCODE_MAXIMUM_LIMITS_X = 11;
    public static final int GROUPCODE_MAXIMUM_LIMITS_Y = 21;
    public static final int GROUPCODE_INSERT_POINT_X = 12;
    public static final int GROUPCODE_INSERT_POINT_Y = 22;
    public static final int GROUPCODE_INSERT_POINT_Z = 32;
    public static final int GROUPCODE_MINIMUM_EXTENTS_X = 14;
    public static final int GROUPCODE_MINIMUM_EXTENTS_Y = 24;
    public static final int GROUPCODE_MINIMUM_EXTENTS_Z = 34;
    public static final int GROUPCODE_MAXIMUM_EXTENTS_X = 15;
    public static final int GROUPCODE_MAXIMUM_EXTENTS_Y = 25;
    public static final int GROUPCODE_MAXIMUM_EXTENTS_Z = 35;
    public static final int GROUPCODE_ELEVATION = 146;
    public static final int GROUPCODE_UCS_ORIGIN_X = 13;
    public static final int GROUPCODE_UCS_ORIGIN_Y = 23;
    public static final int GROUPCODE_UCS_ORIGIN_Z = 33;
    public static final int GROUPCODE_UCS_AXIS_X_X = 16;
    public static final int GROUPCODE_UCS_AXIS_X_Y = 26;
    public static final int GROUPCODE_UCS_AXIS_X_Z = 36;
    public static final int GROUPCODE_UCS_AXIS_Y_X = 17;
    public static final int GROUPCODE_UCS_AXIS_Y_Y = 27;
    public static final int GROUPCODE_UCS_AXIS_Y_Z = 37;
    public static final int GROUPCODE_UCS_ORTHOGRAPHIC_TYPE = 76;
    public static final int GROUPCODE_PAPER_SPACE_BLOCK_RECORD_ID = 330;
    public static final int GROUPCODE_LAST_ACTIVE_VIEWPORT_ID = 331;
    public static final int GROUPCODE_UCS_ID = 345;
    public static final int GROUPCODE_UCS_BASE_ID = 346;
    protected DXFLayout layout;

    public DXFLayoutHandler() {
    }

    @Override
    public void endObject() {
    }

    @Override
    public DXFObject getDXFObject() {
        return this.layout;
    }

    @Override
    public String getObjectType() {
        return DXFConstants.OBJECT_TYPE_LAYOUT;
    }

    @Override
    public void parseGroup(int var1, DXFValue var2) {
        switch(var1) {
            case GROUPCODE_MINIMUM_LIMITS_X:
                this.layout.getLimits().setMinimumX(var2.getDoubleValue());
                break;
            case GROUPCODE_MAXIMUM_LIMITS_X:
                this.layout.getLimits().setMaximumX(var2.getDoubleValue());
                break;
            case GROUPCODE_INSERT_POINT_X:
                this.layout.getInsertPoint().setX(var2.getDoubleValue());
                break;
            case GROUPCODE_UCS_ORIGIN_X:
                this.layout.getOriginUCS().setX(var2.getDoubleValue());
                break;
            case GROUPCODE_MINIMUM_EXTENTS_X:
                this.layout.getExtent().setMinimumX(var2.getDoubleValue());
                break;
            case GROUPCODE_MAXIMUM_EXTENTS_X:
                this.layout.getExtent().setMaximumX(var2.getDoubleValue());
                break;
            case GROUPCODE_UCS_AXIS_X_X:
                this.layout.getXAxisUCS().setX(var2.getDoubleValue());
                break;
            case GROUPCODE_UCS_AXIS_Y_X:
                this.layout.getYAxisUCS().setX(var2.getDoubleValue());
                break;
            case GROUPCODE_MINIMUM_LIMITS_Y:
                this.layout.getLimits().setMinimumY(var2.getDoubleValue());
                break;
            case GROUPCODE_MAXIMUM_LIMITS_Y:
                this.layout.getLimits().setMaximumY(var2.getDoubleValue());
                break;
            case GROUPCODE_INSERT_POINT_Y:
                this.layout.getInsertPoint().setY(var2.getDoubleValue());
                break;
            case GROUPCODE_UCS_ORIGIN_Y:
                this.layout.getOriginUCS().setY(var2.getDoubleValue());
                break;
            case GROUPCODE_MINIMUM_EXTENTS_Y:
                this.layout.getExtent().setMinimumY(var2.getDoubleValue());
                break;
            case GROUPCODE_MAXIMUM_EXTENTS_Y:
                this.layout.getExtent().setMaximumY(var2.getDoubleValue());
                break;
            case GROUPCODE_UCS_AXIS_X_Y:
                this.layout.getXAxisUCS().setY(var2.getDoubleValue());
                break;
            case GROUPCODE_UCS_AXIS_Y_Y:
                this.layout.getYAxisUCS().setY(var2.getDoubleValue());
                break;
            case GROUPCODE_INSERT_POINT_Z:
                this.layout.getInsertPoint().setZ(var2.getDoubleValue());
                break;
            case GROUPCODE_UCS_ORIGIN_Z:
                this.layout.getOriginUCS().setZ(var2.getDoubleValue());
                break;
            case GROUPCODE_MINIMUM_EXTENTS_Z:
                this.layout.getExtent().setMinimumZ(var2.getDoubleValue());
                break;
            case GROUPCODE_MAXIMUM_EXTENTS_Z:
                this.layout.getExtent().setMaximumZ(var2.getDoubleValue());
                break;
            case GROUPCODE_UCS_AXIS_X_Z:
                this.layout.getXAxisUCS().setZ(var2.getDoubleValue());
                break;
            case GROUPCODE_UCS_AXIS_Y_Z:
                this.layout.getYAxisUCS().setZ(var2.getDoubleValue());
                break;
            case GROUPCODE_UCS_ORTHOGRAPHIC_TYPE:
                this.layout.setOrthographicTypeOfUCS(var2.getIntegerValue());
                break;
            case GROUPCODE_ELEVATION:
                this.layout.setElevation(var2.getDoubleValue());
                break;
            case GROUPCODE_PAPER_SPACE_BLOCK_RECORD_ID:
                this.layout.setPaperSpaceBlockID(var2.getValue());
                break;
            case GROUPCODE_LAST_ACTIVE_VIEWPORT_ID:
                this.layout.setLastActiveViewportID(var2.getValue());
                break;
            case GROUPCODE_UCS_ID:
                this.layout.setNamedUCSID(var2.getValue());
                break;
            case GROUPCODE_UCS_BASE_ID:
                this.layout.setBaseUCSID(var2.getValue());
                break;
            default:
                super.parseGroup(var1, var2);
        }

    }

    @Override
    public void startObject() {
        this.layout = new DXFLayout();
        this.plotSettings = this.layout;
    }
}
